package com.yanqu.road.entity.banquet;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.banquet.UserBanquetMember;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.commons.lang.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户宴会
 */
public class UserCrossBanquetData extends DataObject {

    /**
     * 唯一标示
     */
    private String banquetId;

    private String invitationId;

    private String invitationInfo;

    private long userId;

    private int serverId;

    //宴会类型(10001,10002,20001,20002,20003)
    private int type;

    private long openTime;

    private long overTime;

    private boolean isSendReward;

    private long popularity;

    private long integral;

    private int userCount;

    private UserBaseInfo userBaseInfo = new UserBaseInfo(); //玩家基础信息

    private List<Integer> serverList;

    //宴会的状态0是生成状态，1是正式开启状态
    private int status;

    private String endReward = "";//盛宴结束奖励 缓存一下带给客户端，不用保存

    private Map<Long, UserBanquetMember> userBanquetMemberMap = new ConcurrentHashMap<>();

    //正在宴会场景的人
    private List<Long> sceneUserList = new ArrayList<>();


    private String giftTypeAccept;


    /**
     * 主人留言
     */
    private String message = "";

    private int autoOpen;


    public String getInvitationId() {
        return invitationId;
    }

    public void setInvitationId(String invitationId) {
        if (!invitationId.equals(this.invitationId)) {
            this.invitationId = invitationId;
            setUpdateOption();
        }
    }

    public String getInvitationInfo() {
        return invitationInfo;
    }

    public void setInvitationInfo(String invitationInfo) {
        if(!invitationInfo.equals(this.invitationInfo)){
            this.invitationInfo = invitationInfo;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public String getBanquetId() {
        return banquetId;
    }

    public void setBanquetId(String banquetId) {
        if(!banquetId.equals(this.banquetId)){
            this.banquetId = banquetId;
            this.setUpdateOption();
        }
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        if(type != this.type){
            this.type = type;
            this.setUpdateOption();
        }
    }

    public long getOpenTime() {
        return openTime;
    }

    public void setOpenTime(long openTime) {
        if(openTime != this.openTime){
            this.openTime = openTime;
            this.setUpdateOption();
        }
    }

    public long getOverTime() {
        return overTime;
    }

    public void setOverTime(long overTime) {
        if(overTime != this.overTime){
            this.overTime = overTime;
            this.setUpdateOption();
        }
    }

    public boolean isSendReward() {
        return isSendReward;
    }

    public void setSendReward(boolean isSendReward) {
        if(isSendReward != this.isSendReward){
            this.isSendReward = isSendReward;
            this.setUpdateOption();
        }
    }

    public long getPopularity() {
        return popularity;
    }

    public void setPopularity(long popularity) {
        if(popularity != this.popularity){
            this.popularity = popularity;
            this.setUpdateOption();
        }
    }

    public long getIntegral() {
        return integral;
    }

    public void setIntegral(long integral) {
        if(integral != this.integral){
            this.integral = integral;
            this.setUpdateOption();
        }
    }

    public int getUserCount() {
        return userCount;
    }

    public void setUserCount(int userCount) {
        if(userCount != this.userCount){
            this.userCount = userCount;
            this.setUpdateOption();
        }
    }

    public Map<Long, UserBanquetMember> getUserBanquetMemberMap() {
        return userBanquetMemberMap;
    }

    public void setUserBanquetMemberMap(Map<Long, UserBanquetMember> userBanquetMemberMap) {
        this.userBanquetMemberMap = userBanquetMemberMap;
    }


    public boolean isSceneUser(long userId){
        for(Long inUserId : sceneUserList){
            if(inUserId == userId){
                return true;
            }
        }
        return false;
    }

    public void addSceneUser(long userId){
        for(Long inUserId : sceneUserList){
            if(inUserId == userId){
                return;
            }
        }
        sceneUserList.add(userId);
    }

    public void removeSceneUser(long userId){
        sceneUserList.remove(userId);
    }

    public List<Long> getSceneBanquetUser(){
        return new ArrayList<>(sceneUserList);
    }

    public String getEndReward() {
        return endReward;
    }

    public void setEndReward(String endReward) {
        this.endReward = endReward;
    }


    public UserBaseInfo getUserBaseInfo() {
        return userBaseInfo;
    }

    public String getUserBaseInfoJsonStr(){
        if(null == userBaseInfo){
            return "{}";
        }else {
            return JSON.toJSONString(userBaseInfo);
        }
    }

    public void setUserBaseInfo(UserBaseInfo userBaseInfo) {
        this.userBaseInfo = userBaseInfo;
    }


    public int getServerId() {
        return serverId;
    }

    public void setServerId(int serverId) {
        if(serverId != this.serverId){
            this.serverId = serverId;
            setUpdateOption();
        }
    }

    public List<Integer> getServerList() {
        return serverList;
    }

    public void setServerList(List<Integer> serverList) {
        if(!ObjectUtils.equals(serverList,this.serverList)){
            this.serverList = serverList;
            setUpdateOption();
        }
    }

    public void setServerListStr(String serverListStr) {
        if(!serverListStr.equals(StringUtils.listToString(this.serverList,","))){
            this.serverList = StringUtils.stringToIntegerList(serverListStr,",");
            setUpdateOption();
        }
    }

    public String getServerListStr(){
        return  StringUtils.listToString(this.serverList,",");
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        if (status != this.status) {
            this.status = status;
            this.setUpdateOption();
        }
    }

    public String getGiftTypeAccept() {
        return giftTypeAccept;
    }

    public void setGiftTypeAccept(String giftTypeAccept) {
        if (!ObjectUtils.equals(giftTypeAccept, this.giftTypeAccept)) {
            this.giftTypeAccept = giftTypeAccept;
            this.setUpdateOption();
        }
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        if (!this.message.equals(message)) {
            this.message = message;
            this.setUpdateOption();
        }
    }

    public int getAutoOpen() {
        return autoOpen;
    }

    public void setAutoOpen(int autoOpen) {
        if(this.autoOpen != autoOpen) {
            this.autoOpen = autoOpen;
            setUpdateOption();
        }
    }
}

